﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_ChangeProfile : System.Web.UI.UserControl
{
    string Gender = "";
    string Email = "";
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (Request.Cookies["Register"] != null)
        {
            if (Request.Cookies["Register"]["UserName"] != null)
            {
                txtUser.Text = Request.Cookies["Register"]["UserName"];
                Gender = Request.Cookies["Register"]["Gender"];
                Email = Request.Cookies["Register"]["Email"];
                muntiviChangePass.ActiveViewIndex = 0;
                
            }
            else
            {
                lbStatusChangePass.Text = "Bạn chưa đăng nhập. Vui lòng đăng nhập!";
                muntiviChangePass.ActiveViewIndex = 2;
            }
            
        }
        else
        {
            lbStatusChangePass.Text = "Bạn chưa đăng nhập. Vui lòng đăng nhập!";
            muntiviChangePass.ActiveViewIndex = 2;
        }
        
    }
    protected void btResetChangePass_Click(object sender, EventArgs e)
    {
        txtOldPass.Text = "";
        txtNewPass.Text = "";
        txtComfirmNewPass.Text = "";
        txtNewPass.Focus();
    }
    protected void btOkChangePass_Click(object sender, EventArgs e)
    {       
        
    }
    
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        
    }
    protected void btChangePass_Click(object sender, EventArgs e)
    {
        lbStatusChangePass0.Text = "Are you sure? ";
        muntiviChangePass.ActiveViewIndex = 1;
    }
    protected void btNoChangPass_Click(object sender, EventArgs e)
    {
        muntiviChangePass.ActiveViewIndex = 0;
    }

    protected void btYesChangePass_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["Register"]["Password"] == txtOldPass.Text)
        {
            HttpCookie register = new HttpCookie("Register");
            register.Values["Fullname"] = Session["Username"].ToString();
            register.Values["UserName"] = txtUser.Text;
            register.Values["Password"] = txtNewPass.Text;
            register.Values["Gender"] = Gender;
            register.Values["Email"] = Email;
            Response.Cookies.Add(register);            

            CustomValidator1.IsValid = true;
            btYesChangePass.Visible = false;
            btNoChangPass.Visible = false;

            Session["Username"] = "";
            Session.Abandon();
            btYesChangePass.Visible = false;
            btNoChangPass.Visible = false;
            btYesSuccessChangePass.Visible = true;

            lbStatusChangePass0.Text = "Change password success";
            muntiviChangePass.ActiveViewIndex = 1;
        }            
        else
        {
            CustomValidator1.IsValid = false;
            muntiviChangePass.ActiveViewIndex = 0;
        }
    }
    protected void btYesSuccessChangePass_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }
}